/*
 * File: vfsdriver.c
 *
 * Description: This is a driver program for testing your VFS system using an interaction script as input
 * You need to make additional calls to your respective functions as noted in the comments below
 * Make sure the output you display is exactly as per the given specifications for you. Do NOT print
 * any extra output (like debug messages) in the final version of your driver program. You can use this driver program
 * in a in incremental manner as you keep implementing one operator after another. For operators not yet implemented,
 * you can leave the output as given ("TO_BE_DONE"). So you can use this program as your "main" program for testing purposes.
 *
 * DO NOT write the full code for operators in the driver program! You must only CALL your functions from here.
 *
 * Usage: vfsdriver <scriptfilename>
 */

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include "../include/vfs.h"
#include "../include/mount_vfs.h"
#include "../include/unmount_vfs.h"
#include "../include/make_directory.h"
#include "../include/delete_directory.h"
#include "../include/list_directory.h"
#include "../include/add_files.h"
#include "../include/list_file.h"
#include "../include/search_file.h"
#include "../include/update_file.h"
#include "../include/export_file.h"
#include "../include/copy_file.h"
#include "../include/move_file.h"
#include "../include/vfs_errorcodes.h"

#define BUFSIZE 200
#define CMDSIZE 30
#define PARSIZE 100

/*void create_vfs ( char *P1, int P2 );
void mount_vfs ( char *P1 );
void unmountvfs ( char *P1 );
void makedir ( char *P1, char *P2 );
void deletedir ( char *P1 );
void movedir ( char *P1, char *P2 );
void listdir ( char *P1, int P2, char *P3 );
void addfile ( char *P1, char *P2, char *P3 );
void listfile ( char *P1, char *P2 );
void updatefile ( char *P1, char *P2 );
void removefile ( char *P1 );
void movefile ( char *P1, char *P2 );
void copyfile ( char *P1, char *P2 );
void exportfile ( char *P1, char *P2 );
void searchfile ( char *P1, char *P2 );
*/
void processcommand( char [], char [], char [], char [] );

int main( int argc, char *argv[] )
{
	FILE *scriptfp;
	char linebuffer[BUFSIZE];
	char command[CMDSIZE], par1[PARSIZE], par2[PARSIZE], par3[PARSIZE];
	char *token;
	
	roots.naryroot=NULL;
	roots.bstRoot=NULL;

	if( argc != 2 ){
		fprintf(stderr,"Usage: vfsdriver <scriptfile>\n");
		return(1);
	}

	if( (scriptfp=fopen(argv[1],"r")) == NULL ){
		fprintf(stderr,"Unable to open script file: %s\n", argv[1]);
		return(2);
	}

	while( fgets(linebuffer, sizeof(linebuffer), scriptfp) != NULL ){
		/* This output is for debugging... do not uncomment in final version */
		/*
		printf("==================================================\n");
		printf("Processing: %s", linebuffer);
		printf("==================================================\n");
		*/

		/* Remove the extra newline character in the end of line */
		linebuffer[ strlen(linebuffer)-1 ] = '\0';
		
		/* Get the command and the parameters using tokenizer */
		strcpy( command, (token = strtok(linebuffer, " ")) == NULL ? "" : token );
		
		strcpy( par1, (token = strtok(NULL, " ")) == NULL ? "" : token );
		strcpy( par2, (token = strtok(NULL, " ")) == NULL ? "" : token );
		strcpy( par3, (token = strtok(NULL, " ")) == NULL ? "" : token );
		/* printf("Command:%s:p1:%s:p2:%s:p3:%s\n",command, par1, par2, par3); */

		processcommand( command, par1, par2, par3 );
	}
}

void processcommand( char command[], char P1[], char P2[], char P3[] )
{
	int status;
	FILE *out;

	out = fopen("/usr/tempvfs.out","a");

	if( strcmp(command, "createvfs") == 0 ){

		if((strcmp(P1,"")==0)||(strcmp(P2,"")==0)){
			fprintf(out,"createvfs_FAILURE %s\n",ERR_VFS_CREATE_00);
			fseek(out,0,SEEK_END);
		}

		else{
			if(mounted==1)
			{
				fprintf(out,"createvfs_FAILURE %s\n",ERR_VFS_CREATE_06);
				fseek(out,0,SEEK_END);
			}
			
			else
			{	
				int size = atoi(P2);
				status = create_vfs (P1,size);
	
				if(status==0){
					fprintf(out,"%s","createvfs_SUCCESS\n");
					fseek(out,0,SEEK_END);
				}
		
				if(status==1){
					fprintf(out,"createvfs_FAILURE %s\n",ERR_VFS_CREATE_01);
					fseek(out,0,SEEK_END);
				}
	
				if(status==2){
					fprintf(out,"createvfs_FAILURE %s\n",ERR_VFS_CREATE_02);
					fseek(out,0,SEEK_END);
				}
		
				if(status==3){
					fprintf(out,"createvfs_FAILURE %s\n",ERR_VFS_CREATE_03);
					fseek(out,0,SEEK_END);
				}
		
				if(status==4){
					fprintf(out,"createvfs_FAILURE %s\n",ERR_VFS_CREATE_04);
					fseek(out,0,SEEK_END);
				}
		
				if(status==5){
					fprintf(out,"createvfs_FAILURE %s\n",ERR_VFS_CREATE_05);
					fseek(out,0,SEEK_END);
				}
			
				if(status==7){
					fprintf(out,"createvfs_FAILURE %s\n",ERR_VFS_CREATE_07);
					fseek(out,0,SEEK_END);
				}
			}
	    	}	
	}	

	else if( strcmp(command, "mountvfs") == 0 ){

		if((strcmp(P1,"")==0)){
			fprintf(out,"mountvfs_FAILURE %s\n",ERR_VFS_MOUNT_00);
			fseek(out,0,SEEK_END);
			
		}

		else{
		
			if(mounted == 1){
				fprintf(out,"mountvfs_FAILURE %s\n",ERR_VFS_MOUNT_04);
				fseek(out,0,SEEK_END);
			}

			else{
				status = mount_vfs (P1);

				if(status==0){
					fprintf(out,"mountvfs_SUCCESS\n");
					fseek(out,0,SEEK_END);
					mounted=1;
				}
		
				if(status==1){
					fprintf(out,"mountvfs_FAILURE %s\n",ERR_VFS_MOUNT_01);
					fseek(out,0,SEEK_END);
				}
		
				if(status==2){
					fprintf(out,"mountvfs_FAILURE %s\n",ERR_VFS_MOUNT_02);
					fseek(out,0,SEEK_END);
				}
		
				if(status==3){
					fprintf(out,"mountvfs_FAILURE %s\n",ERR_VFS_MOUNT_03);
					fseek(out,0,SEEK_END);
				}
		
				if(status==4){
					fprintf(out,"mountvfs_FAILURE %s\n",ERR_VFS_MOUNT_04);
					fseek(out,0,SEEK_END);
				}
			 }
		}
	
	}

	else if( strcmp(command, "unmountvfs") == 0 ){

		if((strcmp(P1,"")==0)){
			fprintf(out,"unmountvfs_FAILURE %s\n",ERR_VFS_UNMOUNT_00);
			fseek(out,0,SEEK_END);
		}

		else{

			if(mounted == 0){
				fprintf(out,"unmountvfs_FAILURE %s\n",ERR_VFS_UNMOUNT_04);
				fseek(out,0,SEEK_END);
			}

			else{
				status = unmount_vfs (P1);
	
				if(status==0){
					fprintf(out,"unmountvfs_SUCCESS\n");
					fseek(out,0,SEEK_END);
					mounted=0;
				}
		
				if(status==1){
					fprintf(out,"unmountvfs_FAILURE %s\n",ERR_VFS_UNMOUNT_01);
					fseek(out,0,SEEK_END);
				}
	
				if(status==2){
					fprintf(out,"unmountvfs_FAILURE %s\n",ERR_VFS_UNMOUNT_02);
					fseek(out,0,SEEK_END);
				}
	
				if(status==3){
					fprintf(out,"unmountvfs_FAILURE %s\n",ERR_VFS_UNMOUNT_03);
					fseek(out,0,SEEK_END);
				}		
		
				if(status==4){
					fprintf(out,"unmountvfs_FAILURE %s\n",ERR_VFS_UNMOUNT_04);
					fseek(out,0,SEEK_END);
				}
			}	
		}

	}

	else if( strcmp(command, "makedir") == 0 ){

		if((strcmp(P1,"")==0)||(strcmp(P2,"")==0)){
			fprintf(out,"makedir_FAILURE %s\n",ERR_VFS_MAKEDIR_00);
			fseek(out,0,SEEK_END);
		}

		else{
			if(mounted == 0){
				fprintf(out,"makedir_FAILURE %s\n",ERR_VFS_MAKEDIR_04);
				fseek(out,0,SEEK_END);
			}

			else{
				status = makedir(P1,P2);
			
				if(status==0){
					fprintf(out,"makedir_SUCCESS\n");
					fseek(out,0,SEEK_END);
				}
	
				if(status==1){
					fprintf(out,"makedir_FAILURE %s\n",ERR_VFS_MAKEDIR_01);
					fseek(out,0,SEEK_END);
				}
		
				if(status==2){
					fprintf(out,"makedir_FAILURE %s\n",ERR_VFS_MAKEDIR_02);
					fseek(out,0,SEEK_END);
				}
		
				if(status==3){
					fprintf(out,"makedir_FAILURE %s\n",ERR_VFS_MAKEDIR_03);
					fseek(out,0,SEEK_END);
				}
			}
		}		
	}		

	else if( strcmp(command, "deletedir") == 0 ){

		if(strcmp(P1,"")==0){
			fprintf(out,"deletedir_FAILURE %s\n",ERR_VFS_DELETEDIR_00);
			fseek(out,0,SEEK_END);
		}

		else{
	
			if(mounted == 0){
				fprintf(out,"deletedir_FAILURE %s\n",ERR_VFS_DELETEDIR_04);
				fseek(out,0,SEEK_END);
			}
		
			else{
				status = deletedir (P1);
		
				if(status==0){
					fprintf(out,"deletedir_SUCCESS\n");
					fseek(out,0,SEEK_END);
				}
				
				if(status==1){
					fprintf(out,"deletedir_FAILURE %s\n",ERR_VFS_DELETEDIR_01);
					fseek(out,0,SEEK_END);
				}
		
				if(status==2){
					fprintf(out,"deletedir_FAILURE %s\n",ERR_VFS_DELETEDIR_02);
					fseek(out,0,SEEK_END);
				}
		
				if(status==3){
					fprintf(out,"deletedir_FAILURE %s\n",ERR_VFS_DELETEDIR_03);
					fseek(out,0,SEEK_END);
				}

				if(status==5){
					fprintf(out,"deletedir_FAILURE %s\n",ERR_VFS_DELETEDIR_05);
					fseek(out,0,SEEK_END);
				}
			}
		}		
	}	

	else if( strcmp(command, "movedir") == 0 ){

		if((strcmp(P1,"")==0)||(strcmp(P2,"")==0)){
			fprintf(out,"movedir_FAILURE %s\n",ERR_VFS_MOVEDIR_00);
			fseek(out,0,SEEK_END);
		}
		
		else{
			if(mounted == 0){
				fprintf(out,"movedir_FAILURE %s\n",ERR_VFS_MOVEDIR_08);
				fseek(out,0,SEEK_END);
			}

			else{

				status = movedir (P1,P2);

				if(status==0){
					fprintf(out,"movedir_SUCCESS\n");
					fseek(out,0,SEEK_END);
				}
		
				if(status==1){
					fprintf(out,"movedir_FAILURE %s\n",ERR_VFS_MOVEDIR_01);
					fseek(out,0,SEEK_END);
				}
		
				if(status==2){
					fprintf(out,"movedir_FAILURE %s\n",ERR_VFS_MOVEDIR_02);
					fseek(out,0,SEEK_END);
				}
		
				if(status==3){
					fprintf(out,"movedir_FAILURE %s\n",ERR_VFS_MOVEDIR_03);
					fseek(out,0,SEEK_END);
				}
		
				if(status==4){
					fprintf(out,"movedir_FAILURE %s\n",ERR_VFS_MOVEDIR_04);
					fseek(out,0,SEEK_END);
				}
		
				if(status==5){
					fprintf(out,"movedir_FAILURE %s\n",ERR_VFS_MOVEDIR_05);
					fseek(out,0,SEEK_END);
				}

				if(status==6){
					fprintf(out,"movedir_FAILURE %s\n",ERR_VFS_MOVEDIR_06);
					fseek(out,0,SEEK_END);
				}

				if(status==7){
					fprintf(out,"movedir_FAILURE %s\n",ERR_VFS_MOVEDIR_07);
					fseek(out,0,SEEK_END);
				}
			}
		}

	}
	
	else if( strcmp(command, "listdir") == 0 ){

		if((strcmp(P1,"")==0)||(strcmp(P2,"")==0)||(strcmp(P3,"")==0)){
			fprintf(out,"listdir_FAILURE %s\n",ERR_VFS_LISTDIR_00);
			fseek(out,0,SEEK_END);
		}

		else{
			if(mounted == 0){
				fprintf(out,"listdir_FAILURE %s\n",ERR_VFS_LISTDIR_04);
				fseek(out,0,SEEK_END);
			}

			else{

				int flag = atoi(P2);
				status = listdir (P1,flag,P3);
		
				if(status==0){
					fprintf(out,"listdir_SUCCESS\n");
					fseek(out,0,SEEK_END);
				}
		
				if(status==1){
					fprintf(out,"listdir_FAILURE %s\n",ERR_VFS_LISTDIR_01);
					fseek(out,0,SEEK_END);
				}
			
				if(status==2){
					fprintf(out,"listdir_FAILURE %s\n",ERR_VFS_LISTDIR_02);
					fseek(out,0,SEEK_END);
				}
		
				if(status==3){
					fprintf(out,"listdir_FAILURE %s\n",ERR_VFS_LISTDIR_03);
					fseek(out,0,SEEK_END);
				}

			}
		}
	}		
		
	else if( strcmp(command, "addfile") == 0 ){

		if((strcmp(P1,"")==0)||(strcmp(P2,"")==0)||(strcmp(P3,"")==0)){
			fprintf(out,"addfile_FAILURE %s\n",ERR_VFS_ADDFILE_00);
			fseek(out,0,SEEK_END);
		}

		else{

			if(mounted == 0){
				fprintf(out,"addfile_FAILURE %s\n",ERR_VFS_ADDFILE_07);
				fseek(out,0,SEEK_END);
			}

			else{
				status = addfiles (P1,P2,P3);
		
				if(status==0){
					fprintf(out,"addfile_SUCCESS\n");
					fseek(out,0,SEEK_END);
				}
		
				if(status==1){
					fprintf(out,"addfile_FAILURE %s\n",ERR_VFS_ADDFILE_01);
					fseek(out,0,SEEK_END);
				}
		
				if(status==2){
					fprintf(out,"addfile_FAILURE %s\n",ERR_VFS_ADDFILE_02);
					fseek(out,0,SEEK_END);
				}
		
				if(status==3){
					fprintf(out,"addfile_FAILURE %s\n",ERR_VFS_ADDFILE_03);
					fseek(out,0,SEEK_END);
				}
		
				if(status==4){
					fprintf(out,"addfile_FAILURE %s\n",ERR_VFS_ADDFILE_04);
					fseek(out,0,SEEK_END);
				}

				if(status==5){
					fprintf(out,"addfile_FAILURE %s\n",ERR_VFS_ADDFILE_05);
					fseek(out,0,SEEK_END);
				}

				if(status==6){
					fprintf(out,"addfile_FAILURE %s\n",ERR_VFS_ADDFILE_06);
					fseek(out,0,SEEK_END);
				}
			}
		}
	}	

	else if( strcmp(command, "listfile") == 0 ){

		if((strcmp(P1,"")==0)||(strcmp(P2,"")==0)){
			fprintf(out,"listfile_FAILURE %s\n",ERR_VFS_LISTFILE_00);
			fseek(out,0,SEEK_END);
		}

		else{
			if(mounted == 0){
				fprintf(out,"listfile_FAILURE %s\n",ERR_VFS_LISTFILE_06);
				fseek(out,0,SEEK_END);
			}
		
			else{
				status = listfile (P1,P2);
			
				if(status==0){
					fprintf(out,"listfile_SUCCESS\n");
					fseek(out,0,SEEK_END);
				}
		
				if(status==1){
					fprintf(out,"listfile_FAILURE %s\n",ERR_VFS_LISTFILE_01);
					fseek(out,0,SEEK_END);
				}
		
				if(status==2){
					fprintf(out,"listfile_FAILURE %s\n",ERR_VFS_LISTFILE_02);
					fseek(out,0,SEEK_END);
				}
		
				if(status==3){
					fprintf(out,"listfile_FAILURE %s\n",ERR_VFS_LISTFILE_03);
					fseek(out,0,SEEK_END);
				}
		
				if(status==4){
					fprintf(out,"listfile_FAILURE %s\n",ERR_VFS_LISTFILE_04);
					fseek(out,0,SEEK_END);
				}
			
				if(status==5){
					fprintf(out,"listfile_FAILURE %s\n",ERR_VFS_LISTFILE_05);
					fseek(out,0,SEEK_END);
				}
			}
		}
			
	}
	else if( strcmp(command, "updatefile") == 0 ){

		if((strcmp(P1,"")==0)||(strcmp(P2,"")==0)){
			fprintf(out,"updatefile_FAILURE %s\n",ERR_VFS_UPDATEFILE_00);
			fseek(out,0,SEEK_END);
		}
		else{
			if(mounted == 0){
				fprintf(out,"updatefile_FAILURE %s\n",ERR_VFS_UPDATEFILE_06);	
				fseek(out,0,SEEK_END);
			}
		
			else{
				status = updatefile (P1,P2);
	
				if(status==0){
					fprintf(out,"updatefile_SUCCESS\n");
					fseek(out,0,SEEK_END);
				}
		
				if(status==1){
					fprintf(out,"updatefile_FAILURE %s\n",ERR_VFS_UPDATEFILE_01);
					fseek(out,0,SEEK_END);
				}
		
				if(status==2){
					fprintf(out,"updatefile_FAILURE %s\n",ERR_VFS_UPDATEFILE_02);
					fseek(out,0,SEEK_END);
				}
		
				if(status==3){
					fprintf(out,"updatefile_FAILURE %s\n",ERR_VFS_UPDATEFILE_03);
					fseek(out,0,SEEK_END);
				}
	
				if(status==4){
					fprintf(out,"updatefile_FAILURE %s\n",ERR_VFS_UPDATEFILE_04);
					fseek(out,0,SEEK_END);
				}

				if(status==5){
					fprintf(out,"updatefile_FAILURE %s\n",ERR_VFS_UPDATEFILE_05);
					fseek(out,0,SEEK_END);
				}
			}
		}
	}		

	else if( strcmp(command, "removefile") == 0 ){

		if((strcmp(P1,"")==0)){
			fprintf(out,"removefile_FAILURE %s\n",ERR_VFS_REMOVEFILE_00);
			fseek(out,0,SEEK_END);
		}
		else{
			if(mounted == 0){
				fprintf(out,"removefile_FAILURE %s\n",ERR_VFS_REMOVEFILE_02);
				fseek(out,0,SEEK_END);
			}

			else{
				status = deletedir(P1);
	
				if(status==0){
					fprintf(out,"removefile_SUCCESS\n");
					fseek(out,0,SEEK_END);
				}
	
				if(status==1){
					fprintf(out,"removefile_FAILURE %s\n",ERR_VFS_REMOVEFILE_01);
					fseek(out,0,SEEK_END);
				}
        if(status==2){
          fprintf(out,"removefile_FAILURE %s\n",ERR_VFS_REMOVEFILE_01);
          fseek(out,0,SEEK_END);
        }
			}
		}
	}		
	else if( strcmp(command, "movefile") == 0 ){

		if((strcmp(P1,"")==0)||(strcmp(P2,"")==0)){
			fprintf(out,"movefile_FAILURE %s\n",ERR_VFS_MOVEFILE_00);
			fseek(out,0,SEEK_END);
		}
		else{
			if(mounted == 0){
				fprintf(out,"movefile_FAILURE %s\n",ERR_VFS_MOVEFILE_06);
				fseek(out,0,SEEK_END);
			}
			else{
				status = movefile (P1,P2);
	
				if(status==0){
					fprintf(out,"movefile_SUCCESS\n");
					fseek(out,0,SEEK_END);
				}
	
				if(status==1){
					fprintf(out,"movefile_FAILURE %s\n",ERR_VFS_MOVEFILE_01);
					fseek(out,0,SEEK_END);
				}
	
				if(status==2){
					fprintf(out,"movefile_FAILURE %s\n",ERR_VFS_MOVEFILE_02);
					fseek(out,0,SEEK_END);
				}

				if(status==3){
					fprintf(out,"movefile_FAILURE %s\n",ERR_VFS_MOVEFILE_03);
					fseek(out,0,SEEK_END);
				}

				if(status==4){
					fprintf(out,"movefile_FAILURE %s\n",ERR_VFS_MOVEFILE_04);
					fseek(out,0,SEEK_END);
				}
			}
		}
	}

	else if( strcmp(command, "copyfile") == 0 ){

		if((strcmp(P1,"")==0)||(strcmp(P2,"")==0)){
			fprintf(out,"copyfile_FAILURE %s\n",ERR_VFS_COPYFILE_00);
			fseek(out,0,SEEK_END);
		}
		else{
			if(mounted == 0){
				fprintf(out,"copyfile_FAILURE %s\n",ERR_VFS_COPYFILE_07);
				fseek(out,0,SEEK_END);
			}
			else{
		
			status = copyfile (P1,P2);

				if(status==0){
					fprintf(out,"copyfile_SUCCESS\n");
					fseek(out,0,SEEK_END);
				}

				if(status==1){
					fprintf(out,"copyfile_FAILURE %s\n",ERR_VFS_COPYFILE_01);
					fseek(out,0,SEEK_END);
				}
	
				if(status==2){
					fprintf(out,"copyfile_FAILURE %s\n",ERR_VFS_COPYFILE_02);
					fseek(out,0,SEEK_END);
				}

				if(status==3){
					fprintf(out,"copyfile_FAILURE %s\n",ERR_VFS_COPYFILE_03);
					fseek(out,0,SEEK_END);
				}

				if(status==4){
					fprintf(out,"copyfile_FAILURE %s\n",ERR_VFS_COPYFILE_04);
					fseek(out,0,SEEK_END);
				}

				if(status==5){
					fprintf(out,"copyfile_FAILURE %s\n",ERR_VFS_COPYFILE_05);
					fseek(out,0,SEEK_END);
				}
			
				if(status==6){
					fprintf(out,"copyfile_FAILURE %s\n",ERR_VFS_COPYFILE_06);
					fseek(out,0,SEEK_END);
				}
			}
		}
	}

	else if( strcmp(command, "exportfile") == 0 ){

		if((strcmp(P1,"")==0)||(strcmp(P2,"")==0)){
			fprintf(out,"exportfile_FAILURE %s\n",ERR_VFS_EXPORTFILE_00);
			fseek(out,0,SEEK_END);
		}
		else{
			if(mounted == 0){
				fprintf(out,"exportfile_FAILURE %s\n",ERR_VFS_EXPORTFILE_07);
				fseek(out,0,SEEK_END);
			}
	
			else{
		
				status = exportfile (P1,P2);

				if(status==0){
						fprintf(out,"exportfile_SUCCESS\n");
					fseek(out,0,SEEK_END);
				}
	
				if(status==1){
					fprintf(out,"exportfile_FAILURE %s\n",ERR_VFS_EXPORTFILE_01);
					fseek(out,0,SEEK_END);
				}

				if(status==2){
					fprintf(out,"exportfile_FAILURE %s\n",ERR_VFS_EXPORTFILE_02);
					fseek(out,0,SEEK_END);
				}

				if(status==3){
					fprintf(out,"exportfile_FAILURE %s\n",ERR_VFS_EXPORTFILE_03);
					fseek(out,0,SEEK_END);
				}
	
				if(status==4){
					fprintf(out,"exportfile_FAILURE %s\n",ERR_VFS_EXPORTFILE_04);
					fseek(out,0,SEEK_END);
				}

				if(status==5){
					fprintf(out,"exportfile_FAILURE %s\n",ERR_VFS_EXPORTFILE_05);
					fseek(out,0,SEEK_END);
				}
	
				if(status==6){
					fprintf(out,"exportfile_FAILURE %s\n",ERR_VFS_EXPORTFILE_06);
					fseek(out,0,SEEK_END);
				}

			}
		}

	}
	
	else if( strcmp(command, "searchfile") == 0 ){

		if((strcmp(P1,"")==0)||(strcmp(P2,"")==0)){
			fprintf(out,"searchfile_FAILURE %s\n",ERR_VFS_SEARCHFILE_00);
			fseek(out,0,SEEK_END);
		}
		else{
			if(mounted == 0){
				fprintf(out,"searchfile_FAILURE %s\n",ERR_VFS_SEARCHFILE_03);
				fseek(out,0,SEEK_END);
			}

			else{
	
				status = searchfile (P1,P2);

				if(status==0){
					fprintf(out,"searchfile_SUCCESS\n");
					fseek(out,0,SEEK_END);
				}
	
				if(status==1){
					fprintf(out,"searchfile_FAILURE %s\n",ERR_VFS_SEARCHFILE_01);
					fseek(out,0,SEEK_END);
				}

				if(status==2){
					fprintf(out,"searchfile_FAILURE %s\n",ERR_VFS_SEARCHFILE_02);
					fseek(out,0,SEEK_END);
				}
			}
		}
	}

	else if( strcmp(command, "contentsearch") == 0 ){

		if((strcmp(P1,"")==0)||(strcmp(P2,"")==0)){
			fprintf(out,"content_Search_FAILURE %s\n",ERR_VFS_CONTENT_SEARCH_00);
			fseek(out,0,SEEK_END);
		}
		else{
			if(mounted == 0){
				fprintf(out,"content_Search_FAILURE %s\n",ERR_VFS_CONTENT_SEARCH_02);
				fseek(out,0,SEEK_END);
			}

			else{
	
				status = contentsearch(P1,P2);

				if(status==0){
					fprintf(out,"content_Search_SUCCESS\n");
					fseek(out,0,SEEK_END);
				}
	
				if(status==1){
					fprintf(out,"content_Search_FAILURE %s\n",ERR_VFS_CONTENT_SEARCH_01);
					fseek(out,0,SEEK_END);
				}
			}
		}
	}
	
	else{
		fprintf(out,"Ignoring invalid command %s\n", command);
		fseek(out,0,SEEK_END);
	}


	fclose(out);
}

